import requests
from lxml import etree


class DailyNewsCollect:
    def __init__(self):
        self.url = "https://www.163.com/dy/media/T1603594732083.html"
        self.headers = {
        'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
        'Accept': '*/*',
        'Host': 'www.163.com',
        'Connection': 'keep-alive'
        }
    
    def _get_best_news_data(self):
        response = requests.get(url=self.url, headers=self.headers)

        xml = etree.HTML(response.text)
        all_news_list = xml.xpath('//div[@class="tab_content"]//li/a/@href')

        return all_news_list[0]
    

    def get_news_content(self):
        url = self._get_best_news_data()
        response = requests.get(url=url, headers=self.headers)

        xml = etree.HTML(response.text)
        news_content = xml.xpath('//div[@class="post_body"]//p[2]')[0].xpath('string(.)')

        print(news_content)
        return news_content
        

if __name__ == '__main__':
    DailyNewsCollect().get_news_content()